@extends('layouts.art')
@section('content')

<form class="form-horizontal" method="post" action="/art/{{$art->id}}">
   {{csrf_field()}}
        {{ method_field('PATCH') }}
        <div class="form-group">
            <label for="inputEmail3" class="col-sm-2 control-label">标题</label>
            <div class="col-sm-8">
                <input type="title" class="form-control" id="title" name="title" placeholder="{{$art->title}}" value="">

            </div>
        </div>


        <div class="form-group">
            <label for="inputEmail3" class="col-sm-2 control-label">内容</label>
            <div class="col-sm-8">
                <textarea class="form-control" rows="5" id="content" name="content" placeholder="{{$art->content}}"></textarea>
            </div>
        </div>


        <div class="form-group">
            <div class="col-sm-offset-2 col-sm-10">
                <button type="submit" class="btn btn-default">修改</button>
                 <button type="button" id="yulan" class="btn btn-default">预览</button>
            </div>
        </div>
    </form>

	<div class="col-sm-8">
                预览标题:<input type="title" class="form-control" id="title1" name="title" value="">
    </div>
    <div class="col-sm-8">
                预览内容:<textarea class="form-control" rows="5" id="content1" name="content" ></textarea>
    </div>
   
    <script>
    	/*$('#yulan').click(function(){
    		alert(123);
    	})*/
    	$('#yulan').click(function(data){
    		var title = $('#title').val();
    		var content = $('#content').val();
    		//console.log(content);
    		$.post('/art/{{$art->id}}/ajax',{title:title,content:content},function(data){
    			//eval("var a ="+data);
    			//document.write(data);
    			var obj = new Function("return" + data)();
    			//alert(obj.title);
    			$('#title1').val(obj.title);
    			$('#content1').val(obj.content);
    			 
    		});

    	});

    	$.ajaxSetup({
		   headers: { 'X-CSRF-Token' : $('meta[name=_token]').attr('content') }
		});
		    	


    </script>
@endsection